package com.whnk.attendance.controller;

import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.whnk.attendance.vo.*;
import com.whnk.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import com.whnk.attendance.service.IProjectClassifyInfoService;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 项目分类列表Controller
 *
 * @author whnk
 * @date 2021-12-14
 */
@Api(tags = "项目分类列表Controller")
@RestController
@RequestMapping("/projectClassify")
public class ProjectClassifyInfoController extends BaseController
{
    @Autowired
    private IProjectClassifyInfoService projectClassifyInfoService;

    /**
     * 分页查询项目分类列表
     */
    @ApiOperation(value = "分页查询项目分类列表",notes = "分页查询项目分类列表")
    @PreAuthorize(hasPermi = "attendance:info:list")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam(value = "项目分类信息", required = false) ProjectClassifyInfoQueryVo projectClassifyInfoQueryVo)
    {
        startPage();
        List<ProjectClassifyInfoListVo> list = projectClassifyInfoService.selectProjectClassifyInfoListVoList(projectClassifyInfoQueryVo);
        return getDataTable(list);
    }

    /**
     * 根据逻辑主键查询项目分类信息
     */
    @ApiOperation(value = "根据逻辑主键查询项目分类信息",notes = "根据逻辑主键查询项目分类信息")
    @PreAuthorize(hasPermi = "attendance:info:query")
    @GetMapping(value = "/query/{proClaId}")
    public AjaxResult getInfo(@ApiParam(value = "逻辑主键",required = false) @PathVariable("proClaId") Long proClaId)
    {
        return AjaxResult.success(projectClassifyInfoService.selectProjectClassifyInfoListVoByProClaId(proClaId));
    }

    /**
     * 新增项目分类信息
     */
    @ApiOperation(value = "新增项目分类信息",notes = "新增项目分类信息")
    @PreAuthorize(hasPermi = "attendance:info:add")
    @Log(title = "项目分类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@ApiParam(value = "项目分类信息", required = false) @Validated @RequestBody ProjectClassifyInfoUpdateVo projectClassifyInfoUpdateVo)
    {
        if(!projectClassifyInfoService.checkProClaNum(projectClassifyInfoUpdateVo)){
            return AjaxResult.error("新增项目分类信息" + projectClassifyInfoUpdateVo.getProClaNum() + "失败，该项目分类信息已存在");
        }
        return toAjax(projectClassifyInfoService.insertProjectClassifyInfo(projectClassifyInfoUpdateVo)) ;
    }

    /**
     * 修改项目分类列
     */
    @ApiOperation(value = "修改项目分类列表",notes = "修改项目分类列表")
    @PreAuthorize(hasPermi = "attendance:info:edit")
    @Log(title = "项目分类列", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@ApiParam(value = "项目分类信息", required = false) @RequestBody ProjectClassifyInfoUpdateVo projectClassifyInfoUpdateVo)
    {
        if(!projectClassifyInfoService.checkProClaNum(projectClassifyInfoUpdateVo)){
            return AjaxResult.error("修改项目分类信息" + projectClassifyInfoUpdateVo.getProClaNum() + "失败，该项目分类信息已存在");
        }
        return toAjax(projectClassifyInfoService.updateProjectClassifyInfo(projectClassifyInfoUpdateVo));
    }

    /**
     * 批量删除项目分类信息
     */
    @ApiOperation(value = "批量删除项目分类信息",notes = "批量删除项目分类信息")
    @PreAuthorize(hasPermi = "attendance:info:remove")
    @Log(title = "项目分类信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{proClaIds}")
    public AjaxResult remove(@ApiParam(value = "逻辑主键",required = false) @PathVariable Long[] proClaIds)
    {
        return toAjax(projectClassifyInfoService.deleteProjectClassifyInfoByProClaIds(proClaIds));
    }

    /**
     * 导入项目分类信息
     */
    @ApiOperation(value = "导入项目分类信息",notes = "导入项目分类信息")
    @PreAuthorize(hasPermi = "attendance:info:import")
    @Log(title = "项目分类信息", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult imports(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<ProjectClassifyInfoListVo> util = new ExcelUtil<>(ProjectClassifyInfoListVo.class);
        List<ProjectClassifyInfoListVo> projectClassifyInfoList = util.importExcel(file.getInputStream());
        String message = projectClassifyInfoService.importData(projectClassifyInfoList, updateSupport);
        return AjaxResult.success(message);
    }

    /**
     * 导出项目分类信息
     */
    @ApiOperation(value = "导出项目分类信息",notes = "导出项目分类信息")
    @PreAuthorize(hasPermi = "attendance:info:export")
    @Log(title = "项目分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam(value = "项目分类信息", required = false) ProjectClassifyInfoQueryVo projectClassifyInfoQueryVo) throws IOException
    {
        List<ProjectClassifyInfoListVo> list = projectClassifyInfoService.selectProjectClassifyInfoListVoList(projectClassifyInfoQueryVo);
        ExcelUtil<ProjectClassifyInfoListVo> util = new ExcelUtil<ProjectClassifyInfoListVo>(ProjectClassifyInfoListVo.class);
        util.exportExcel(response, list, "项目分类信息数据");
    }

//    /**
//     * 新增修改界面交付区域下拉框
//     */
//    @GetMapping("/addAreaList")
//    @ApiOperation(value = "新增修改界面交付区域下拉框",notes = "新增修改界面交付区域下拉框")
//    public TableDataInfo areaInfoList(){
//        List<ProjectClassifyInfoAreaVo> list = projectClassifyInfoService.areaInfoList();
//        return getDataTable(list);
//    }
//
//    /*
//     * 新增修改界面社保分类编号下拉框
//     */
//    @GetMapping("/addSocialInsNumList")
//    @ApiOperation(value = "新增修改界面社保分类编号下拉框",notes = "新增修改界面社保分类编号下拉框")
//    public TableDataInfo socialInsNumList(){
//        List<ProjectClassifyInfoSocialInsNumVo> list = projectClassifyInfoService.socialInsNumList();
//        return getDataTable(list);
//    }

    /*
     * 项目分类编号id，项目分类名称name接口
     */
    @GetMapping(value = "/projectClassifyList")
    @ApiOperation(value = "项目分类编号id，项目分类名称name接口",notes = "项目分类编号id，项目分类名称name接口")
    public TableDataInfo projectClassifyList(){
        List<ProjectClassifyListVo> list = projectClassifyInfoService.projectClassifyList();
        return getDataTable(list);
    }
}
